package com.gilgamesh.mall.member.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gilgamesh.mall.sdk.bean.member.UserEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

/**
 * @author yanm
 * @date 2021/1/8 14:11
 **/
@Mapper
public interface UserDao extends BaseMapper<UserEntity> {
    @Results(
            id = "userDTOMap",value = {
            @Result(column = "id" ,jdbcType = JdbcType.BIGINT,javaType = java.lang.Long.class,property = "id"),
            @Result(column = "user_name" ,jdbcType = JdbcType.VARCHAR,javaType = java.lang.String.class,property = "userName"),
            @Result(column = "user_id" ,jdbcType = JdbcType.VARCHAR,javaType = java.lang.String.class,property = "userId"),
            @Result(column = "password" ,jdbcType = JdbcType.VARCHAR,javaType = java.lang.String.class,property = "password"),
            @Result(column = "sex" ,jdbcType = JdbcType.VARCHAR,javaType = java.lang.String.class,property = "sex"),

            @Result(column = "age",jdbcType = JdbcType.INTEGER,javaType = java.lang.Byte.class,property = "age"),
            @Result(column = "phone_number",jdbcType = JdbcType.VARCHAR,javaType = java.lang.String.class,property = "phoneNumber"),
            @Result(column = "name",jdbcType = JdbcType.VARCHAR,javaType = java.lang.String.class,property = "name"),
            @Result(column = "mail",jdbcType = JdbcType.VARCHAR,javaType = java.lang.String.class,property = "mail"),
            @Result(column = "identity",jdbcType = JdbcType.TINYINT,javaType = java.lang.Byte.class,property = "identity"),
            @Result(column = "create_time",jdbcType = JdbcType.DATETIMEOFFSET,javaType = java.util.Date.class,property = "createTime")

    }
    )

    @Select("select * from t_user where mail =#{mail}")
    UserEntity isExistMail(String mail);

    @Select("select * from t_user where phone_number =#{phoneNumber}")
    UserEntity isExistPhone(String phoneNumber);

    @Insert("insert into t_user(`id`,`user_name`,`user_id`,`password`,`phone_number`,`create_time`) VALUES (#{id},#{userName},#{userId},#{password},#{phoneNumber},#{createTime})")
    Integer addByPhone(UserEntity user);

    @Insert("insert into t_user(`id`,`user_name`,`user_id`,`password`,`mail`,`create_time`) VALUES (#{id},#{userName},#{userId},#{password},#{mail},#{createTime})")
    Integer addByMail(UserEntity user);




}
